package org.uni_hi.lsep.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.MediaTracker;

import javax.swing.ImageIcon;
import javax.swing.JWindow;

public class SplashScreen extends JWindow implements Runnable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 483817146639212650L;
	private ImageIcon ico=null;
	private long _dt=5000L;
	private Component _parent=null;

	public SplashScreen(){}

	public SplashScreen(long displaytime, Component parent){
		_dt=displaytime;
		_parent=parent;
	}

	@Override
	public void run() {
		try{
			ico=new ImageIcon("img/Start.jpg");
			while(ico.getImageLoadStatus()==MediaTracker.LOADING);
			setSize(ico.getIconWidth()+10,ico.getIconHeight()+10);
			setLocationRelativeTo(_parent);

			setVisible(true);
			try
			{
				Thread.sleep(_dt);
			}
			catch (InterruptedException e)
			{
				dispose();
			}
		} catch (NullPointerException e) {
			e.printStackTrace();
		}

		dispose();	
	}

	public void paint(Graphics g)
	{
		g.setColor(Color.LIGHT_GRAY);
		g.fillRect(0, 0, ico.getIconWidth()+10, ico.getIconHeight()+10);
		g.drawImage(ico.getImage(), 5, 5, this);
		//		g.setColor(Color.LIGHT_GRAY);
		//		g.fillRect(ico.getIconWidth(), 5, 5, ico.getIconHeight()+5);
	}


}

